﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AIFSContentManagementSystem.Criteria
{
    public sealed class BooleanExpression : Expression
    {
        public override ExpressionDataType DataType
        {
            get
            {
                return ExpressionDataType.BOOLEAN;
            }
        }

        protected override bool CanCompare(Expression other)
        {
            if (!(other is BooleanExpression))
                return false;

            //See if the values can be parsed as boolean
            bool thisBoolean;
            bool result = bool.TryParse(this.ExpressionElement.RightOperand, out thisBoolean);
            if (!result)
                return false;

            bool otherBoolean;
            result = bool.TryParse(other.ExpressionElement.RightOperand, out otherBoolean);
            if (!result)
                return false;

            //for boolean types it will only matter if they both have same value
            //there is no > < >= or <= for booleans so it is same as if it could not
            //be compared
            if (thisBoolean != otherBoolean)
                return false;

            return true;
        }

        protected override int CompareTo(Expression other)
        {
            //For boolean if it reached here means they matched just return 0
            return 0;
        }
    }
}
